/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pgentity;

import db.DBContext;
import db.PGKeys;
import db.RedisKey;
import pgentity.pool.EntityFactory;
import pgentity.redis.PGRedisSetEntity;
import share.PGException;

/**
 *
 * @author Salm
 */
@EntityFactory(factorier = "loadUsedGiftCode")
public class UsedGiftCode extends PGRedisSetEntity {
    private final String uid;
    private final RedisKey keyUGC;

    private UsedGiftCode(String uid)
    {
        this.uid = uid;
        keyUGC = redisKey(uid);
    }
    
    public static UsedGiftCode getUsedGiftCode(String uid) throws PGException
    {
        return loadUsedGiftCode(uid);
//        return EntityPool.inst().get(UsedGiftCode.class, uid);
    }
    
    public static UsedGiftCode loadUsedGiftCode(String uid)
    {
        return new UsedGiftCode(uid);
    }
    
    public static RedisKey redisKey(String uid)
    {
        return PGKeys.USERS.getChild(uid).getChild(PGKeys.FD_USEDGIFTCODE);
    }
    
    public static void destroy(String uid)
    {
        DBContext.Redis().del(redisKey(uid));
//        EntityPool.inst().remove(UsedGiftCode.class, uid);
    }
    
    @Override
    protected RedisKey redisKey()
    {
        return keyUGC;
    }

    public String getUid() {
        return uid;
    }

    @Override
    public boolean contains(String ID) {
        return super.contains(ID);
    }

    public Object dump()
    {
        return this.getAll();
    }
}
